const DB = require('../db/config');

const DBOP = {
  // 获取书本详情页地址
  async getAllBook() {
    const sql = 'SELECT detailUrl FROM bookinfo';
    const res = await DB.query(sql, []);
    return res;
  },
  // 获取书本读书地址
  async getAllBookAndReadUrl_Null() {
    const sql =
      'SELECT * FROM bookinfo AS bi,bookdetail AS bd WHERE bi.bookName = bd.bookName AND bd.readUrl IS  NULL ';
    const res = await DB.query(sql, []);
    return res;
  },
  // 插入书本详细信息
  async insertBookDetail(value) {
    const sql = 'INSERT INTO bookdetail VALUES (null,?,?,?,?,?,?,?,?,?,?,?,?,?)';
    const res = await DB.query(sql, value);
    return res;
  },
  // 获取所有书籍内容页
  async getAllBookContent() {
    const sql = 'SELECT  *  FROM bookdetail WHERE  id > 2425';
    const res = await DB.query(sql, []);
    return res;
  },
  //  插入书籍章节内容
  async insertBookContent(value) {
    const sql = 'INSERT INTO bookcontent VALUE(null,?,?,?)';
    const res = await DB.query(sql, value);
    return res;
  },
  //  插入作者-书籍
  async insertAuthorBook(value) {
    const sql = 'INSERT INTO author VALUE(NULL, ?, ?) ';
    const res = await DB.query(sql, value);
    return res;
  },
  async updateReadUrl(value) {
    const sql = 'UPDATE  bookdetail SET  readUrl = ? WHERE bookName = ?';
    const res = await DB.query(sql, value);
    return res;
  },
};

module.exports = DBOP;
